﻿// -------------------------------------------------------------------------------------------------------------------------------
// <copyright file="TestConstructorWithSizeParameter.cs" company="Exul">
//     Copyright (c) Exul. All rights reserved.
// </copyright>
// <author>
//     Exul
// </author>
// -------------------------------------------------------------------------------------------------------------------------------

namespace ExulLibrary.Mathematics.LinearAlgebra.Tests.DenseSymmetricMatrixTest
{
    #region Usings

    using System.Diagnostics.CodeAnalysis;

    using ExulLibrary.Exceptions;

    using NUnit.Framework;

    #endregion

    /// <summary>
    ///     Test suite for the constructor with size parameter.
    /// </summary>
    [TestFixture]
    [Category("ExulLibrary.Mathematics.LinearAlgebra.DenseSymmetricMatrix{T}")]
    public sealed class TestConstructorWithSizeParameter
    {
        /// <summary>
        ///     Tests the constructor when size parameter is positive.
        /// </summary>
        /// <param name="size">
        ///     The size of the new matrix.
        /// </param>
        [SuppressMessage(
            "Microsoft.Usage",
            "CA2233:OperationsShouldNotOverflow",
            MessageId = "size+1",
            Justification = "Overflow is considered as unimportant.")]
        [Test]
        public void WhenSizeParameterIsPositive([Values(1, 2)] int size)
        {
            // Act
            var matrix = new DenseSymmetricMatrix<object>(size);

            // Assert
            Assert.That(matrix.RowsCount, Is.EqualTo(size));
            Assert.That(matrix.ColumnsCount, Is.EqualTo(size));
            Assert.That(matrix.IsSquare, Is.True);
            Assert.That(matrix.Values, Is.Not.Null & Has.Length.EqualTo(size * (size + 1) / 2));
        }

        #if SAFE

        /// <summary>
        ///     Tests the constructor when size parameter is negative or equal to zero.
        /// </summary>
        /// <param name="size">
        ///     The size of the new matrix.
        /// </param>
        [Test]
        public void WhenSizeParameterIsNegativeOrZero([Values(-1, 0)] int size)
        {
            // Act and Assert
            Assert.That(
                () => new DenseSymmetricMatrix<object>(size),
                Throws.TypeOf<NegativeOrZeroSizeException>().With.Property("ParamName").EqualTo("matrixSize"));
        }

        #endif
    }
}